// import axios from '@/utils/request'

export default {
  Invoice: {
    form: {
      fields: [
        'status',
        'paidTime'
      ]
    },
    list: {
      export: {
        query: {
          '@display': `{
                  'id' : 'entity.getId()',
                  'outTradeNo' : 'entity.getOutTradeNo()',
                  'status' : '{0: "等待支付",1: "已支付","-1": "已退款","-2": "已取消或支付失败"}[entity.getStatus()]',
                  'scene' : '{"deposit": "充值","order": "订单"}[entity.getScene()]',
                  'gateway' : 'entity.getGateway()',
                  'amount' : 'entity.getAmount()',
                  'refunds' : 'entity.getRefunds()',
                  'payment' : 'entity.getPayment()',
                  'transactionId' : 'entity.getTransactionId()',
                  'paidTime' : 'entity.getPaidTime().format("Y-m-d H:i:s")',
                  'createdTime' : 'entity.getCreatedTime().format("Y-m-d H:i:s")'
              }`,
          'limit': 100000000
        },
        label: {
          'id': 'id',
          'outTradeNo': '编号',
          'status': '状态',
          'scene': '场景',
          'gateway': '方式',
          'amount': '金额',
          'refunds': '退款金额',
          'payment': '付款方式',
          'transactionId': '交易号',
          'paidTime': '支付时间',
          'createdTime': '创建时间'
        }
      },
      // actions: [
      //   { name: 'refund',
      //     position: 'list',
      //     component: {
      //       props: ['record'],
      //       data() {
      //         return {
      //           show: false,
      //           amount: null,
      //           loading: false
      //         }
      //       },
      //       methods: {
      //         refund() {
      //           if (!this.amount || this.amount <= 0) {
      //             this.$message.error('请填写执行金额')
      //             return
      //           }
      //           this.loading = true
      //           axios.get(`/manage/settle-items`, {
      //             params: {
      //               '@filter': `entity.getSettle().getOrderItem().getOrder().getId() == ${this.record.id}`
      //             }
      //           }).then((res) => {
      //             this.$message.success('执行成功')
      //             this.show = false
      //           }).finally(() => {
      //             this.loading = false
      //           })
      //         }
      //       },
      //       render(h) {
      //         if (this.record.scene === 'order' && this.record.gateway) {
      //           return <div>
      //             <el-button nativeOnClick={ () => { this.show = true; this.amount = null } } slot='reference' type='danger' size='small' plain>退款</el-button>

      //             <el-dialog
      //               title='退款'
      //               visible={this.show}
      //               width='50%'
      //               onClose={() => { this.show = false }}
      //             >
      //               <el-form ref='form' label-width='100px'>
      //                 <el-form-item label='id'>
      //                   <span>{this.record.id}</span>
      //                 </el-form-item>
      //                 <el-form-item label='编号'>
      //                   <span>{this.record.outTradeNo}</span>
      //                 </el-form-item>
      //                 <el-form-item label='金额'>
      //                   <span>￥{this.record.amount}</span>
      //                 </el-form-item>
      //                 <el-form-item label='已退金额'>
      //                   <span>￥{this.record.refunds}</span>
      //                 </el-form-item>
      //                 <el-form-item label='执行金额'>
      //                   <el-input v-model={this.amount} type='number' />
      //                 </el-form-item>
      //               </el-form>
      //               <span slot='footer' class='dialog-footer'>
      //                 <el-button onClick={() => { this.show = false }}>取消</el-button>
      //                 <el-button slot='reference' type='primary' loading={this.loading} nativeOnClick={ () => { this.refund() } }>
      //                   { this.loading ? '提交中 ...' : '确认' }
      //                 </el-button>
      //               </span>
      //             </el-dialog>
      //           </div>
      //         }
      //       }
      //     }
      //   }
      // ],
      disabled_actions: ['new', 'delete', 'edit', 'lines'],
      query: {
        '@order': 'entity.id|DESC'
      },
      list_filter: {
        'id': 'ID',
        'outTradeNo': '编号',
        'transactionId': '交易号',
        'payment': '付款方式',
        'status': {
          '__label': '状态',
          '-2': '已取消或支付失败',
          '-1': '已退款',
          '0': '等待支付',
          '1': '已支付'
        },
        'scene': {
          '__label': '场景',
          'deposit': '充值',
          'order': '订单'
        },
        beforePaidTime: {
          expression: 'entity.getPaidTime() >= datetime.get(":value 00:00:00")',
          label: '支付开始时间',
          type: 'date'
        },
        afterPaidTime: {
          expression: 'entity.getPaidTime() <= datetime.get(":value 23:59:59")',
          label: '支付结束时间',
          type: 'date'
        },
        beforeCreatedTime: {
          expression: 'entity.getCreatedTime() >= datetime.get(":value 00:00:00")',
          label: '创建开始时间',
          type: 'date'
        },
        afterCreatedTime: {
          expression: 'entity.getCreatedTime() <= datetime.get(":value 23:59:59")',
          label: '创建结束时间',
          type: 'date'
        }
      },
      list_display: [
        'id',
        { property: 'outTradeNo', label: '编号' },
        {
          property: 'status', label: '状态',
          component: {
            methods: {
              filter: (type, status) => [
                { value: -2, label: '已取消或支付失败', tagType: 'danger' },
                { value: -1, label: '已退款', tagType: 'danger' },
                { value: 0, label: '等待支付', tagType: 'warning' },
                { value: 1, label: '已支付', tagType: 'success' }
              ].find(obj => obj.value === status)[type]
            },
            props: ['data'],
            render(h) {
              return (
                <el-tag type={this.filter('tagType', this.data)}>
                  {this.filter('label', this.data)}
                </el-tag>
              )
            }
          }
        },
        {
          property: 'scene',
          component: {
            props: ['data'],
            data() {
              return {
                tag: { deposit: '充值', order: '订单' }
              }
            },
            render(h) {
              return <span>{this.tag[this.data]}</span>
            }
          }
        },
        'gateway',
        {
          property: 'amount', label: '金额',
          component: {
            props: ['data'],
            render(h) {
              return <span>￥{this.data}</span>
            }
          }
        },
        {
          property: 'refunds', label: '退款金额',
          component: {
            props: ['data'],
            render(h) {
              return <span>￥{this.data}</span>
            }
          }
        },
        { property: 'payment', label: '付款方式' },
        { property: 'transactionId', label: '交易号' },
        'paidTime',
        'createdTime'
      ]
    }
  }
}
